<template>
	<view class="container">
		<view class="o-plr">
			<view class="c-t65 c-tb o-ptb">请输入新手机号</view>
			<u-field
				v-model="phone"
				label="手机号"
				placeholder="请填写手机号"
				
			>
			</u-field>
			<view class="l-fjb" style="margin-bottom: 360rpx;">
				<view class="">
					<u-field
						v-model="code"
						label="验证码"
						placeholder="请填写验证码"
					>
					</u-field>
				</view>
				<view class="">
					<u-toast ref="uToast"></u-toast>
					<u-verification-code :seconds="seconds" @end="end" @start="start" ref="uCode" 
					@change="codeChange"></u-verification-code>
					<u-button @click="getCode" size="mini">{{tips}}</u-button>
				</view>
			</view>
			<u-button type="primary">确定</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: uni.getStorageSync('phone'),
				code: null,
				tips: '',
				// refCode: null,
				seconds: 60,
			}
		},
		onLoad() {
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if(this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			end() {
				this.$u.toast('倒计时结束');
			},
			start() {
				this.$u.toast('倒计时开始');
			}
		}
	}
</script>

<style>
</style>
